package com.neulogistics.contrib.procuredcenter.infrastructure.persistence.repository;

import com.neulogistics.contrib.procuredcenter.domain.model.aggregate.PurchaseOrder;
import com.neulogistics.contrib.procuredcenter.domain.repository.IPurchaseOrderRepository;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.converter.PurchaseOrderEntityPOConverter;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.orm.po.PurchaseOrderPO;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.orm.service.IPurchaseOrderPOService;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class PurchaseOrderRepository implements IPurchaseOrderRepository {
    @Resource
    IPurchaseOrderPOService purchaseOrderPOService;

    @Override
    public void save(PurchaseOrder purchaseOrder) {
        PurchaseOrderPO purchaseOrderPO = PurchaseOrderEntityPOConverter.entityToPO(purchaseOrder);
        purchaseOrderPOService.saveOrUpdate(purchaseOrderPO);
    }

    @Override
    public PurchaseOrder findById(Long id) {
        PurchaseOrderPO purchaseOrderPO = purchaseOrderPOService.getById(id);
        PurchaseOrder purchaseOrder = PurchaseOrderEntityPOConverter.POToEntity(purchaseOrderPO);
        return purchaseOrder;
    }

    @Override
    public void deleteById(Long id) {
        purchaseOrderPOService.removeById(id);
    }
}
